package guoanmaker.provider.business.repository;

import guoanmaker.provider.business.model.OperatorServerClass;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author vladimir.stankovic
 *         <p>
 *         Aug 16, 2016
 */
public interface OperatorServerClassRepository extends JpaRepository<OperatorServerClass, String>, JpaSpecificationExecutor<OperatorServerClass> {
    //	@Query("select u from ProvideUser u left join fetch u.roles r where u.username=:username")
//    public Optional<OperatorServerClass> findByUsername(@Param("username") String username);
    @Query("select t from OperatorServerClass t where t.serverLevel = :serverLevel and t.deleteState=0 ")
    Page<OperatorServerClass> findAllByServerLevel(Pageable pageable, @Param("serverLevel") Integer serverLevel);

    @Query("select t from  OperatorServerClass t where t.parentServerId = :parentServerId and t.deleteState=0")
    ArrayList<OperatorServerClass> findAllByParentServerId(@Param("parentServerId") String parentServerId);
    
    @Query("select t from OperatorServerClass t where t.serverLevel = :serverLevel and t.deleteState=0")
    List<OperatorServerClass> findAllByServerforlevid(@Param("serverLevel") Integer serverLevel);
    
    List<OperatorServerClass> findByIdInAndDeleteStateIs(Collection<String> ids,String deleteState);
    
    List<OperatorServerClass> findByParentServerIdInAndDeleteStateIs(Collection<String> parentServerIds,String deleteState);

    List<OperatorServerClass> findByServerLevelAndDeleteStateIs(Integer serverLevel,String deleteState);
    
    //通过类型等级和服务标记查询服务列表
    List<OperatorServerClass> findByServerLevelAndServerTypeAndDeleteStateIs(Integer serverLevel,Integer serverType,String deleteState);
    
    
    List<OperatorServerClass> findByIdInAndParentServerIdIsAndDeleteStateIs(Collection<String> parentServerIds,String parentServerId,String deleteState);

    List<OperatorServerClass> findByIdInAndServerTypeIsAndDeleteStateIs(Collection<String> parentServerIds,Integer serverType,String deleteState);
    
    List<OperatorServerClass> findByIdInAndServerLevelIsAndDeleteStateIs(Collection<String> parentServerIds,Integer serverLevel,String deleteState);
}
